#!/usr/bin/python
# -*- coding: utf-8 -*-

#-------------------------------------------------
#Create At: 2009-1-24 下午11:36:07 
#Create By: Fla.sam
#
#DESC: 
#
#-------------------------------------------------


from django.db import models
from django.contrib.auth.models import User
from CoreApp.models import Place
from tagging.fields import TagField
import tagging

# Create your models here.

class DesktopItemInfo( models.Model ):
    '''
    base AdItemInfo Model
    '''
    item_name = models.CharField( verbose_name = u'名称', max_length = 100, help_text = u'广告名称' )
    item_start_time = models.DateTimeField( verbose_name = u'开始时间', help_text = u'该广告开始计时开始时间' )
    item_end_time = models.DateTimeField( verbose_name = u'结束时间', help_text = u'该广告计时结束时间' )
    item_play_local = models.ForeignKey( Place, verbose_name = u'广告播放地理位置', help_text = u'该广告投放的地理位置' )
    item_show_status = models.BooleanField( default = False, verbose_name = u'是否显示该广告' )
    #item_tags = TagField(verbose_name='标签', help_text='该条目的标签')
    
tagging.register( DesktopItemInfo )

class DesktopWallpaper( DesktopItemInfo ):
    
    item = models.ImageField( upload_to = '/', verbose_name = u'桌面广告图片', help_text = u'桌面广告图片' )
    
    def __unicode__( self ):
        return  u'桌面背景广告 [ %s ]. [ %s -> %s ],播放地区[ %s ]' % ( self.item_name, self.item_start_time, self.item_end_time, self.item_play_local )
    
    class Meta:
        verbose_name = u'桌面背景广告'
        verbose_name_plural = u'%s管理' % verbose_name
    
class IEHomepageURL( DesktopItemInfo ):
    
    item = models.URLField( verbose_name = u'IE首页URL', help_text = u'设置IE首页的广告连接' )
    
    def __unicode__( self ):
        return  u'IE首页广告 [ %s ]. [ %s -> %s ],播放地区[ %s ]' % ( self.item_name, self.item_start_time, self.item_end_time, self.item_play_local )
    
    class Meta:
        verbose_name = u'IE首页广告'
        verbose_name_plural = u'%s管理' % verbose_name
        
class Count( models.Model ):
    item_hit = models.IntegerField( verbose_name = u'点击/显示 次数', help_text = u'只计数' )
    item_hit_last_datetime = models.DateTimeField( verbose_name = u'最后一次 点击/显示 的时间', help_text = u'计算时间,防止用户刷点击' )
    item_hit_user = models.ForeignKey( User, verbose_name = u'点击用户', help_text = u'该字段指向 广告终端用户' )
    
    class Meta:
        abstract = True

class IECount( Count ):
    item = models.ForeignKey( IEHomepageURL, verbose_name = u'IE首页广告', help_text = u'该字段指向IE首页' )
    
    def __unicode__( self ):
        return u'%s 用户 %s 点击了 %d 次, 最后点击  %s' % ( self.item, self.item_hit_user, self.item_hit, self.item_hit_last_datetime )
    
    class Meta:
        verbose_name = u'IE首页广告统计'
        verbose_name_plural = u'%s管理' % verbose_name
    
class WallpaperCount( Count ):
    items = models.ForeignKey( DesktopWallpaper, verbose_name = u'桌面背景广告', help_text = u'该字段指向桌面广告' )
    
    def __unicode__( self ):
        return u'%s 用户 %s 点击了 %d 次, 最后点击  %s' % ( self.item, self.item_hit_user, self.item_hit, self.item_hit_last_datetime )
    class Meta:
        verbose_name = u'桌面背景广告统计'
        verbose_name_plural = u'%s管理' % verbose_name
        
        